/**
  ETFAna project, Anyang Normal University && IMP-CAS
  \struct vme_block_head
  \brief data structures and specifications for the metadata of a VME block
  \author SUN Yazhou, asia.rabbit@163.com
  \since 2021-10-03
  \date 2021-10-03 last modified
  \attention
  changelog
  <table>
  <tr>  <th>Date         <th>Author      <th>Description                    </tr>
  <tr>  <td>2021-10-03   <td>Asia Sun    <td>file created                   </tr>
  </table>

  \copyright Copyright (c) 2021-2024 Anyang Normal U. && IMP-CAS with LGPLv3 LICENSE
*/

#ifndef vme_block_head_h
#define vme_block_head_h

#include <iostream>

using std::cout;
using std::endl;

// ------------------------ VME BLOCK STRUCTURE ------------------------------//
struct vme_block_head{
  int index; ///< block index
  int ev_num; ///< event number per block
  int last_pos; ///< the position of the last valid data in the block
  int current_event; ///< id of event being read in the block

  vme_block_head(){
    initialize();
  } // end the ctor
  /// \param data: points to the starting point of a block
  void setData(int *data){
    index = data[0];
    ev_num = data[1];
    last_pos = data[2];
    current_event = 0;
  } // end member function setData
  void initialize(){
    index = -1;
    ev_num = -1;
    last_pos = -1;
    /// these two should be set the same, so that finished() is true at the beginning
    current_event = ev_num;
  } // end member function initialize
  void print(){
    cout << "------ VME BLOCK HEADER No. ";
    cout << index;
    cout << " ---------" << endl;
    cout << "index (block no.): " << index << endl;
    cout << "ev_num: " << ev_num << endl;
    cout << "last_pos: " << last_pos << endl;
    cout << "current_event: " << current_event << endl;
  }
  bool finished(){
    return current_event == ev_num;
  }
};

#endif
